﻿using System.Linq.Expressions;

namespace AdminSystem.Repositories
{
    public interface IRepository<TEntity> where TEntity : class
    {
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
        Task<int> DeleteMany(params int[] idList);
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> DeleteMany(List<TEntity> entities);
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 单条添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        TEntity Insert(TEntity entity);
        /// <summary>
        /// 异步添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<TEntity> InsertAsync(TEntity entity);
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> Queryable();
        IQueryable<TEntity> Queryable(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 根据条件查
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 根据条件查按字段排
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="orderby"></param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        Task<List<TEntity>> QueryAsync<TKey>(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, TKey>> orderby, bool Desc = false) where TKey : struct;
        /// <summary>
        /// 查单条
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<TEntity> QueryFirstAsync(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 查全部
        /// </summary>
        /// <returns></returns>
        Task<List<TEntity>> QueryAsync();
    }
}